建立會員功能存取資料庫的方法
public void Register(Members newMember)
{
newMember.Password = Crypto.HashPassword(newMember.Password);//使用Hash將密碼加密
db.Members.Add(newMember);
db.SaveChanges();
}
//判斷登入帳號的狀態
public string LoginCheck(string UserName,string Password)
{
Members LoginMember = db.Members.Find(UserName);
if (LoginMember != null)
{
if (string.IsNullOrWhiteSpace(LoginMember.AuthCode))
{
if (PasswordCheck(LoginMember, Password))
{
return "";
}
else
{
return "帳號密碼輸入錯誤";
}
}
else
{
return "此帳號未經過驗證";
}
}
else
{
return "查無此帳號";
}
}
//比對輸入的密碼經過雜湊後是否相同
public bool PasswordCheck(Members CheckMember,string Password)
{
bool result = CheckMember.Password.Equals(Crypto.HashPassword(Password));
return result;
}
//信箱驗證方法
public string EmailValidate(string UserName,string AuthCode) {
Members ValidateMember = db.Members.Find(UserName);
string ValidateStr = string.Empty;
if (ValidateMember != null)
{
if (ValidateMember.AuthCode == AuthCode)
{
ValidateMember.AuthCode = string.Empty;
db.SaveChanges();
ValidateStr = "帳號信箱驗證完成!";
}
else
{
ValidateStr = "驗證錯誤!";
}
}
else
{
ValidateStr = "資料傳送錯誤!";
}
return ValidateStr;
}